const express = require("express")
const url = require("url")
const app = express()

const adminLogin = require("./data/admin_login.json")
const vipLogin = require("./data/vip_login.json")

const adminInfo = require("./data/admin_info.json")
const vipInfo = require("./data/vip_info.json")

const adminRouters = require("./data/admin_routers.json")
const vipRouters = require("./data/vip_routers.json")



app.get("/login", (req, res) => {
  const user = url.parse(req.url, true).query.user

  if(user === "admin") {
    res.send(adminLogin)
  } else {
    res.send(vipLogin)
  }
})

app.get("/getInfo", (req, res) => {
  const user = url.parse(req.url, true).query.user

  if(user === "admin") {
    res.send(adminInfo)
  } else {
    res.send(vipInfo)
  }
})

app.get("/getRouters", (req, res) => {
  // const user = url.parse(req.url, true).query.user

  console.log(res, "getRouters")

  // if(user === "admin") {
    res.send(adminRouters)
  // } else {
  //   res.send(vipRouters)
  // }
})

app.post("/logout", (req, res) => {
  console.log(req.body)
  const user = url.parse(req.url, true).query.user

  if(user === "admin") {
    res.send(adminRouters)
  } else {
    res.send(vipRouters)
  }
})

app.listen('3000', function() {
  console.log("3000服务器启动了")
})